package com.zhiyou100.dao;

import com.zhiyou100.entity.Score;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public class ScoreDaoImp   implements   ScoreDao{
    @Autowired
    private SessionFactory  factory;
    private Session  getSession(){
        return factory.openSession();
    }
    public List<Score> getAllFenYe(Integer seid, int startIndex, int pageSize) {
        Query query=getSession().createQuery("from com.zhiyou100.entity.Score  sc where sc.exam.eid=:seid order by sc.snumber desc");
        query.setInteger("seid",seid);
        query.setFirstResult(startIndex);
        query.setMaxResults(pageSize);
        return query.list();
    }
    public void addOne(Score o) {
        getSession().save(o);
    }
    public void deleteOne(Integer id) {
         Session session=getSession();
         Score  score=session.get(Score.class,id);
         session.delete(score);
    }

    public void updateOne(Score o) {
      getSession().update(o);
    }

    public List<Score> getAll() {
        return getSession().createQuery("from com.zhiyou100.entity.Score").list();
    }

    @Override
    public Score getOne(Integer integer) {
        return getSession().get(Score.class,integer);
    }
}
